package org.alis.smallcc.designpatterns.behavior.memento;

import org.alis.smallcc.designpatterns.behavior.state.ForwardState;
import org.alis.smallcc.designpatterns.behavior.state.PlayState;
import org.alis.smallcc.designpatterns.behavior.state.State;
import org.alis.smallcc.designpatterns.behavior.state.StopState;
import org.alis.smallcc.designpatterns.behavior.state.SuspendState;

/**
 * 测试备忘录模式
 * 
 * @author luochuan
 */
public class Main {
	public static void main(String[] args) {
		// 先创建一个发起者 
		Originator originator = new DVDOriginator();
		// 然后创建需要的状态
		State play = new PlayState();
		State forward= new ForwardState();
		State suspend = new SuspendState();
		State stop = new StopState();
		// 创建一个备忘录书籍
		CareTaker taker = new StackCareTaker();
		originator.setState(play);
		originator.saveCurrentState(taker);
		originator.setState(forward);
		originator.saveCurrentState(taker);
		
		originator.setState(suspend);
		originator.saveCurrentState(taker);
		
		originator.setState(play);
		originator.saveCurrentState(taker);
		
		originator.reversal(taker);
		originator.reversal(taker);
		originator.reversal(taker);
		
		originator.setState(stop);
		originator.saveCurrentState(taker);
		
		originator.reversal(taker);
		
		
		play.action(originator);
		play.action(originator);
		System.out.println(originator.getOriginator()+"状态是->"+originator.getState());
		suspend.action(originator);
	}
}
